import { createStore,Store } from "vuex"
import todoState from "./modules/to-do-list"
import { InjectionKey } from "vue"

export const key:InjectionKey<Store<State>> = Symbol()


export interface State {
  taskList:any,
  count:number,
  loading:boolean
}

export interface Task {
  name:string,
  isfinished:boolean
}

export const store = createStore<State>({
  modules:{
    todoState
  },
  state: {
    taskList:[],
    count:0,
    loading:false
  },
  mutations:{
    createTask(state: State ,params:Task):void {
      state.taskList.push(params)
    },
  
    deleteTask(state:State,index:number):void {
      state.taskList.splice(index,1)
    },
  
    // 方法的参数也要定义类型，不知道就定义为 any
    updateTask(state:State, params:any):void {
      const { index, status } = params
      state.taskList[index].isfinished = status 
    },

    // 显示loading
    showLoading(state) {
      state.loading = true
    },

    // 隐藏loading
    hideLoading(state) {
      state.loading = false
    }

  },
  actions:{}
})





